<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>我的分享</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/dist/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>

<script type="text/html" id="barDemo">
    <a lay-event="del">
        <i class="layui-icon layui-icon-refresh" style="font-size: 18px;"></i></a>
   <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>-->
</script>

<script src="layui/dist/layui.js" charset="utf-8"></script>
<script th:inline='none'>
    layui.use('table', function() {
        var table = layui.table;
        //方法级渲染
        table.render({
            elem: '#LAY_table_user'
            , url: 'getShareFile'
            , cols: [[
                {checkbox: true, fixed: true}
                , {field: 'shareName', title: '文件名', width: 200}
                , {field: 'shareType', title: '文件链接', width: 300, sort:true}
                , {field: 'uploadTime', title: '分享日期', width: 300, templet: "<div>{{layui.util.toDateString(d.uploadTime,'yyyy-MM-dd HH:mm:ss')}}</div>"}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 200}
            ]]
            , page: true
            , id: 'testReload'
            , parseData: function (res) {//res为原始返回数据
                console.log(res);
                return {
                    "code": 0,// 解析接口状态
                    "msg": res.msg,//解析提示文本
                    "count": res.count,//解析数据长度
                    "data": res.data//解析数据列表
                };
            }
        });
    });
</script>
<script th:inline='none'>
    layui.use('table', function() {
        var table = layui.table;
        var $=layui.$;
        //监听表格复选框选择
        table.on('checkbox(demo)', function (obj) {
            console.log(obj)
        });
        //监听工具条
        table.on('tool(user)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('是否确定取消分享？', function (index) {
                    obj.del();
                    layer.close(index);
                });
                $.ajax({
                    url: 'deleteShare',
                    type: "get",
                    sync: false,
                    data: {shareName: data.shareName,id: data.id},
                    dataType: "json",
                    success: function (res) {
                        if (res.code === 0) {
                            layer.open({
                                title: '提示信息',
                                content: '取消分享成功！',
                                btn: ['确认'],
                                yes: function () {
                                    window.location.reload();
                                }
                            })
                        } else {
                            layer.alert(res.msg);
                        }
                    },
                    error: function () {
                        layui.alert("系统出错，请联系管理员！")
                    }
                })
            }
            else if(obj.event === 'edit'){
                layer.prompt({title: '请输入有效时长', formType: 2}, function(text, index){
                    layer.close(index);
                    layer.msg('文件分享有效期为：'+text);
                });
            }
        });
    });
</script>

</body>
</html>